package com.favccxx.search.domain;

import java.util.List;

/**
 * @author favccxx
 */
public interface CommonRepo<ID> {

    /**
     * query all data
     *
     * @param clazz data class
     * @param <T>   data type
     * @return data list
     */
    <T> List<T> findAll(Class<T> clazz);

    /**
     * query data by id
     *
     * @param clazz data class
     * @param id    data id
     * @param <T>   data type
     * @return data list
     */
    <T> T findById(Class<T> clazz, ID id);

    /**
     * query data by id list
     *
     * @param clazz data class
     * @param ids   data id list
     * @param <T>   data type
     * @return data list
     */
    <T> List<T> findByIds(Class<T> clazz, List<ID> ids);

    /**
     * save data
     *
     * @param obj data object
     * @param <T> data type
     * @return saved data
     */
    <T> T save(T obj);

    /**
     * delete data
     *
     * @param obj data object
     * @param <T> data type
     * @return count of deleted data
     */
    default <T> long delete(T obj) {
        return 0;
    }

    /**
     * delete data by id
     *
     * @param id    data id
     * @param clazz data class
     * @param <T>   data type
     * @return count of deleted data
     */
    <T> long deleteById(ID id, Class<T> clazz);

    /**
     * update data
     *
     * @param id     data id
     * @param newObj new data object
     * @param <T>    data type
     * @return count of deleted data
     */
    <T> long update(ID id, T newObj);

}
